<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>欢迎登录/华硕ASUS商城</title>
    <script src="./js/vue.js"></script>
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/login/index.css">
    <link rel="stylesheet" href="./css/reg/index.css">
</head>

<body>
    <div id="app">
        <div class="header"><a href="/index"><img src="./img/login/logo.png" alt=""></a></div>
        <div class="containers">
            <div class="rightbox">
                <form action="" class="login">
                    <h2>注册</h2>
                    <p class="part">
                        <input type="text" name="username" v-model="username" placeholder="用户名">
                    </p>
                    <p class="part">
                        <input type="password" name="password" v-model="password" placeholder="密码">
                    </p>
                    <p class="part">
                        <input type="text" name="phone" v-model="phone" placeholder="电话号码">
                    </p>
                    <div class="checked">
                        性别:
                        <input type="radio" name="sex" value="男" v-model="sex"><span style="width: 20px;">男</span>
                        <input type="radio" name="sex" value="女" v-model="sex"><span style="width: 20px;">女</span>
                    </div>
                    <p class="part">
                        <input type="number" name="age" v-model="age" placeholder="年龄">
                    </p>
                    <p class="address">
                        <input type="text" name="address" v-model="address" placeholder="家庭地址">
                    </p>
                    <div class="btn" @click="reg">注册</div>
                    <div class="more">
                        <a href="./login" class="reg">返回密码登录</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <script src="./js/axios.js"></script>
    <!-- <script src="./js/layer/layer.js"></script> -->
    <script>
        const vm = new Vue({
            el: "#app",
            data() {
                return {
                    username: '',
                    password: '',
                    sex: '男',
                    address: '',
                    age: null,
                    phone: ''
                }
            },
            methods: {
                reg() {
                    axios.post('/users/add', {
                        username: this.username,
                        password: this.password,
                        sex: this.sex,
                        address: this.address,
                        age: this.age,
                        phone: this.phone
                    }).then(res => {
                        console.log(res);
                        if (res.data.code == 200) {
                            alert(res.data.msg)
                            setTimeout(() => {
                                location = './login'
                            }, 500)
                        } else {
                            alert(res.data.msg)
                        }
                    })
                }
            },
        })
    </script>
</body>

</html>